#!/bin/sh

# chroot_reboot: Reboots the computer when lapply doesn't appear in ps output.

lapplyStarted=0

while [ $lapplyStarted -eq 0 ]; do
	sleep 15
	if /bin/test -n "$(ps -A | grep lapply | grep -v grep) print $0 }')"
	then
		lapplyStarted=1
	fi
done

# Once we get here, we know that lapply has started. We should really make sure 
# that no pre-apply scripts are calling lapply after this script is started.

lapplyStarted=1

while [ $lapplyStarted -eq 1 ]; do
	sleep 15
	if /bin/test -n "$(ps -A | grep lapply | grep -v grep) print $0 }')"
	then
		lapplyStarted=0
	fi
done

/sbin/reboot
